package com.sc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sc.mapper.StudyFileMapper;
import com.sc.mapper.StudyNoteMapper;
import com.sc.pojo.StudyFile;
import com.sc.pojo.StudyNote;
import com.sc.service.StudyNoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class StudyNoteServiceImpl implements StudyNoteService {
    @Autowired
    StudyNoteMapper mapper;

    @Autowired
    StudyFileMapper sfm;

    public PageInfo<StudyNote> stushow(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<StudyNote> list=mapper.stushow();
        return new PageInfo<>(list);
    }
    @Override
    public int add(StudyNote s) {
        return  mapper.insertSelective(s);
    }

    @Override
    public List<StudyNote> queryAll() {
        return mapper.stushow();
    }

    @Override
    public StudyNote queryByCid(Integer cid) {
        return mapper.selectByPrimaryKey(cid);
    }



    @Override
    public int updateStudyNote(StudyNote note) {
       int i=mapper.updateByPrimaryKey(note);
       return i;
    }

    @Override
    public StudyNote getStudyNoteByNid(Integer nid) {
        StudyNote note=mapper.selectByPrimaryKey(nid);
        return null;
    }

    @Override
    public int aadNote(StudyNote note, StudyFile file) {
        mapper.insertSelective(note);
        int nid = mapper.MaxId();

        file.setNid(nid);
        return sfm.insertSelective(file);

    }
    @Override
    public StudyNote selectByPrimaryKey(Integer nid) {
        return mapper.selectByPrimaryKey(nid);
    }

    @Override
    public int deleteStudyNote(Integer nid) {
        int i=mapper.deleteByPrimaryKey(nid);
        return i;
    }
}
